///////////////////////////////////////////////////////////////////////
//  CS 3716 (Winter 2012), Assignment #4                       		 //
//  Program File Name: MRCompare.java                          		 //
//       Student Name: Jonathan Hart-Wall, Adam Murphy         		 //
//					   Yifu Liang, Joshua Dowling			   		 //
//         Login Name: jcwhw1, agm264 , n96yl, n23jdd                //
//              MUN #: 200933455, 200933133, 200565679, 200703684    //
///////////////////////////////////////////////////////////////////////

/**
 * Import Comparator package.
 */
import java.util.Comparator;

public class MRCompare implements Comparator<MovieRec>{
	
	/**
	 * Compare method between 2 MovieRec Objects.
	 * If name of MovieRec a equals name of MovieRec b, it will compare their ReleaseYears, and return the smallest one first.
	 * Else, it will compare the names of MovieRecs a and b, and return them in alphabetical order
	 */
	public int compare(MovieRec a, MovieRec b) {		
		if (a.getName().toUpperCase().compareTo(b.getName().toUpperCase()) == 0)
		{
			if (a.getReleaseYear() > b.getReleaseYear())
				return 1;
			else if (a.getReleaseYear() < b.getReleaseYear())
				return -1;
			else
				return 0;
		}
		else{
		return a.getName().toUpperCase().compareTo(b.getName().toUpperCase());
		}
	}
}
